package com.gift.recommendation.modules.admin.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.Base.PageData;
import com.gift.recommendation.config.TokenPass;
import com.gift.recommendation.modules.admin.biz.FestivalImpl;
import com.gift.recommendation.modules.admin.dto.FestivalListReq;
import com.gift.recommendation.modules.admin.dto.FestivalRsp;
import com.gift.recommendation.modules.admin.dto.FestivalReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2023/1/16
 */
@RestController
@RequestMapping("/gift/festival")
@Api(tags = "节假日管理")
@Validated
public class FestivalController {

    @Autowired
    private FestivalImpl festival;

    @ApiOperation(value = "获取当前最近节日信息")
    @RequestMapping(path = "/get-pass",method = RequestMethod.GET)
    @TokenPass
    public BaseResponse getPass(){
        FestivalRsp festivalRsp = festival.getPass();
        return BaseResponse.success(festivalRsp);
    };

    @ApiOperation(value = "添加节日")
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public BaseResponse festivalAdd(@RequestBody FestivalReq req){
        festival.addFestival(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "修改节日")
    @RequestMapping(path = "/change",method = RequestMethod.POST)
    public BaseResponse festivalChange(@RequestBody FestivalReq req){
        festival.changeFestival(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "删除节日")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse festivalChange(@RequestParam Long id){
        festival.deleteFestival(id);
        return BaseResponse.success();
    };

    @ApiOperation(value = "节日列表")
    @RequestMapping(path = "/list",method = RequestMethod.POST)
    public BaseResponse<PageData<FestivalRsp>> festivalList(@RequestBody FestivalListReq req){
        PageData<FestivalRsp> result = festival.festivalList(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "通过主键查询节日")
    @RequestMapping(path = "/searchById",method = RequestMethod.GET)
    public BaseResponse festivalSearchById(@RequestParam Long id){
        FestivalRsp result = festival.selectByPrimaryKey(id);
        return BaseResponse.success(result);
    };
}
